// -------------------------------------------------
// BlinKit - BlinKit Library
// -------------------------------------------------
//   File Name: qjs_screen.cpp
// Description: Bindings for Screen
//      Author: Ziming Li
//     Created: 2022-05-02
// -------------------------------------------------
// Copyright (C) 2022 MingYang Software Technology.
// -------------------------------------------------

#include "./qjs_bindings.h"

#include "blinkit/blink/renderer/bindings/core/qjs/qjs.h"
#include "blinkit/blink/renderer/bindings/core/qjs/qjs_c_function_list_entries.h"
#include "blinkit/blink/renderer/core/frame/screen.h"

/**
 * https://developer.mozilla.org/en-US/docs/Web/API/Screen
 */

namespace BlinKit {
namespace qjs {

static JSValue GetAvailHeight(JSContext *ctx, JSValueConst thisVal)
{
    Screen *scr = ScriptWrappable::Cast<Screen>(thisVal);
    return JS_NewInt32(ctx, scr->availHeight());
}

static JSValue GetAvailLeft(JSContext *ctx, JSValueConst thisVal)
{
    Screen *scr = ScriptWrappable::Cast<Screen>(thisVal);
    return JS_NewInt32(ctx, scr->availLeft());
}

static JSValue GetAvailTop(JSContext *ctx, JSValueConst thisVal)
{
    Screen *scr = ScriptWrappable::Cast<Screen>(thisVal);
    return JS_NewInt32(ctx, scr->availTop());
}

static JSValue GetAvailWidth(JSContext *ctx, JSValueConst thisVal)
{
    Screen *scr = ScriptWrappable::Cast<Screen>(thisVal);
    return JS_NewInt32(ctx, scr->availWidth());
}

JSValue CreateScreenPrototype(JSContext *ctx)
{
    static const JSCFunctionListEntry Funcs[] = {
        CGetSetEntry("availHeight", GetAvailHeight, nullptr),
        CGetSetEntry("availLeft", GetAvailLeft, nullptr),
        CGetSetEntry("availTop", GetAvailTop, nullptr),
        CGetSetEntry("availWidth", GetAvailWidth, nullptr)
    };

    JSValue ret = JS_NewObject(ctx);
    JS_SetPropertyFunctionList(ctx, ret, Funcs, std::size(Funcs));
    return ret;
}

} // namespace qjs
} // namespace BlinKit
